package com.ruoyi.web.controller.system.indexweb;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IndexCode;
import com.ruoyi.system.service.IIndexCodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二维码Controller
 * 
 * @author ruoyi
 * @date 2021-07-24
 */
@Controller
@RequestMapping("/system/code")
public class IndexCodeController extends BaseController
{
    private String prefix = "system/code";

    @Autowired
    private IIndexCodeService indexCodeService;


    /**
     * 查询二维码列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IndexCode indexCode)
    {
        startPage();
        List<IndexCode> list = indexCodeService.selectIndexCodeList(indexCode);
        return getDataTable(list);
    }

    /**
     * 导出二维码列表
     */
    @Log(title = "二维码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IndexCode indexCode)
    {
        List<IndexCode> list = indexCodeService.selectIndexCodeList(indexCode);
        ExcelUtil<IndexCode> util = new ExcelUtil<IndexCode>(IndexCode.class);
        return util.exportExcel(list, "二维码数据");
    }


    /**
     * 新增保存二维码
     */
    @Log(title = "二维码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IndexCode indexCode)
    {
        indexCode.setCreateTime(new Date(System.currentTimeMillis()));
        indexCode.setUpdateTime(new Date(System.currentTimeMillis()));
        return toAjax(indexCodeService.insertIndexCode(indexCode));
    }

    /**
     * 修改保存二维码
     */
    @Log(title = "二维码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IndexCode indexCode)
    {
        indexCode.setUpdateTime(new Date(System.currentTimeMillis()));
        return toAjax(indexCodeService.updateIndexCode(indexCode));
    }

    /**
     * 删除二维码
     */
    @Log(title = "二维码", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(indexCodeService.deleteIndexCodeByIds(ids));
    }
}
